<%-- 
    Document   : Log01010
    Created on : Nov 17, 2012, 7:44:54 AM
    Author     : Cimela
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <title>Search Timesheet</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        
        <link href="<%= request.getContextPath()%>/styles/layout.css" rel="stylesheet"
              type="text/css" media="screen" />
        <script src="<%=request.getContextPath()%>/js/arial.js"></script>
        <script src="<%=request.getContextPath()%>/js/cuf_run.js"></script>
        <script src="<%=request.getContextPath()%>/js/cufon-yui.js"></script>
        <script src="<%=request.getContextPath()%>/js/dateUtil.js"></script>
        <script src="<%=request.getContextPath()%>/js/employee.js"></script>
        <script src="<%=request.getContextPath()%>/js/index.js"></script>
        <script src="<%=request.getContextPath()%>/js/menu.js"></script>
        <script src="<%=request.getContextPath()%>/js/tableUtil.js"></script>
        <script src="<%=request.getContextPath()%>/js/log/log02010.js"></script>
        <script src="<%=request.getContextPath()%>/js/pay/pay01010.js"></script>

    </head>
    <body id="top">

        <c:if test="${empty sessionScope.USER}">
            <% response.sendRedirect(request.getContextPath() + "/index.jsp");%>
        </c:if>

        <div class="wrapper col1">
            <div id="header">
                <div id="logo">
                    <h1><a href="<%=request.getContextPath()%>/welcome.jsp">BusinessToday</a></h1>
                    <p><strong>Free CSS Website Template</strong></p>
                </div>
                <div id="newsletter">
                    <p><i>Welcome, ${sessionScope.ROLE}
                            <font color="red" size="4">
                                <strong> ${sessionScope.USER}</strong>
                            </font></i>
                    </p>
                    <p align="right"><a href="<%= request.getContextPath()%>/LogoutController">Log out</a> </p>
                </div>
                <br class="clear" />
            </div>
        </div>

        <%@include file="/jsp/common/menu_timesheet_field.jsp" %>


        <div class="wrapper col5" style="height: 50%;">
            <div id="container">

                <!---->

                <script type="text/javascript" src="<%=request.getContextPath()%>/js/dateUtil.js"></script>
                <script type="text/javascript">
                    function validate(form) {
                        //var fromdate = form.txtFrom.value;
                        var fromdate = document.getElementsByName("txtFrom")[0].value;
                        //var todate = form.txtTo.value;
                        var todate = document.getElementsByName("txtTo")[0].value;
                        var error = [];
                        if (!isDate(fromdate)){
                            error[error.length] = "You must enter a validate from date (dd/MM/yyyy)";
                        }
                        if (!isDate(todate)){
                            error[error.length] = "You must enter a validate to date (dd/MM/yyyy)";
                        }
                        if(error.length>0){
                            executeError(error);
                            return false;
                        }
                        return true;
                    }
                    function executeError(errors){
                        var msg = "There is some errors...\n";
                        for (var i =0 ; i < errors.length; i++){
                            var numErr = i+1;
                            msg += "\n" + numErr + " - " + errors[i];
                        }
                        alert(msg);
                    }
                </script>

                <h1>Timesheet</h1>
                <form action="<%=request.getContextPath()%>/TimesheetController" method="POST">
                    From: <input style="width: 100px" type="text" name="txtFrom" />
                    To:   <input style="width: 100px" type="text" name="txtTo" />
                    Project:
                    <c:set var="pjlist" value="${sessionScope.listPj}"  ></c:set>
                    <select name="cbProject" style ="width: 150px">
                        <option value="All">All</option>
                        <c:import url="/WEB-INF/project.xml" var="xml"/>
                        <x:parse var="doc" xml="${xml}" scope="session"/>
                        <x:forEach var="proj" select="$doc//name">
                            <option value="<x:out select="$proj"/>" ><x:out select="$proj"/></option>
                        </x:forEach>
                    </select>
                    Status:
                    <select name="cbStatus" >
                        <option value="All">All</option>
                        <option value="approved">approved</option>
                        <option value="unapproved">unapproved</option>
                        <option value="rejected">rejected</option>
                    </select>
                    <input type="submit" name="btAction" value="Search" onclick="return validate(this);" />
                </form>
                <br/>

                <c:set var = "info" value="${requestScope.TSheet}"/>
                <c:if test ="${not empty info}">
                    <form action="TimesheetController" >
                        <table border="1">
                            <thead>
                                <tr>
                                    <th></th>
                                    <th>Date</th>
                                    <th>Description</th>
                                    <th>Project</th>
                                    <th>Duration</th>
                                    <th>Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                <c:forEach var="timesheet" items="${info}">
                                    <tr>
                                        <td width="15px"> <input type="checkbox" name="chkChoose" value="${timesheet.id}"/>
                                            <input type="hidden" name="txtID" value="${timesheet.id}" /> </td>
                                        <td width="100px" > ${timesheet.datetime} </td>
                                        <td width="300px" > ${timesheet.description} </td>
                                        <td width="200px" > ${timesheet.project} </td>
                                        <td width="20px"  > ${timesheet.duration} </td>
                                        <td width="80px"  > ${timesheet.status} </td>
                                    </tr>
                                </c:forEach>
                            </tbody>
                        </table>
                        <br/>
                        <input type="submit" name="btAction" value="Update"/>
                        <input type="submit" name="btAction" value="Delete"/>
                    </form>
                </c:if>

                <!---->

                <br class="clear" />
            </div>
        </div>

        <%@include file="/jsp/common/footer_field.jsp" %>
        <%@include file="/jsp/common/copyright_field.jsp" %>

    </body>
</html>